/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
#include <string.h>
#include <jni.h>
#include <android/log.h>
#include <fcntl.h>// contact theopen(),close(),read(),write() and so on!
#include <sys/ioctl.h>

#define GPIO_IOC_MAGIC 0x90
#define COLD_LED_CONTROL       _IOW(GPIO_IOC_MAGIC, 0x1, uint32_t)
#define WARM_LED_CONTROL       _IOW(GPIO_IOC_MAGIC, 0x2, uint32_t)
#define COLD_KEY_CONTROL       _IOW(GPIO_IOC_MAGIC, 0x3, uint32_t)
#define WARM_KEY_CONTROL       _IOW(GPIO_IOC_MAGIC, 0x4, uint32_t)

#define DEVICE_NAME     "/dev/gpio_control"   //device point



void Java_com_ts_host_N_closeAll(JNIEnv* env, jobject thiz) {
	int gpio_fd = open(DEVICE_NAME, O_RDWR);
	if (gpio_fd == -1) {//open fail


	}

	else

	{

		ioctl(gpio_fd, COLD_LED_CONTROL, 1); //关闭冷水led
		ioctl(gpio_fd, WARM_LED_CONTROL, 1); //关闭温水led
		ioctl(gpio_fd, COLD_KEY_CONTROL, 1); //关闭冷水阀
		ioctl(gpio_fd, WARM_KEY_CONTROL, 1); //关闭温水阀
		close(gpio_fd); //close device
	}
}

void Java_com_ts_host_N_closeColdLed(JNIEnv* env, jobject thiz) {
	int gpio_fd = open(DEVICE_NAME, O_RDWR);
	if (gpio_fd == -1) {//open fail


	}

	else

	{

		ioctl(gpio_fd, COLD_LED_CONTROL, 1); //关闭冷水led
		close(gpio_fd); //close device
	}
}

void Java_com_ts_host_N_closeWarmLed(JNIEnv* env, jobject thiz) {
	int gpio_fd = open(DEVICE_NAME, O_RDWR);
	if (gpio_fd == -1) {//open fail


	}

	else

	{

		ioctl(gpio_fd, WARM_LED_CONTROL, 1); //关闭温水led
		close(gpio_fd); //close device
	}
}

void Java_com_ts_host_N_closeColdWater(JNIEnv* env, jobject thiz) {
	int gpio_fd = open(DEVICE_NAME, O_RDWR);
	if (gpio_fd == -1) {//open fail


	}

	else

	{

		ioctl(gpio_fd, COLD_KEY_CONTROL, 1); //关闭冷水阀
		close(gpio_fd); //close device
	}
}

void Java_com_ts_host_N_closeWarmWater(JNIEnv* env, jobject thiz) {
	int gpio_fd = open(DEVICE_NAME, O_RDWR);
	if (gpio_fd == -1) {//open fail


	}

	else

	{

		ioctl(gpio_fd, WARM_KEY_CONTROL, 1); //关闭温水阀
		close(gpio_fd); //close device
	}
}

void Java_com_ts_host_N_openAll(JNIEnv* env, jobject thiz) {
	int gpio_fd = open(DEVICE_NAME, O_RDWR);
	if (gpio_fd == -1) {//open fail


	}

	else

	{
		ioctl(gpio_fd, COLD_LED_CONTROL, 0); //打开冷水led
		ioctl(gpio_fd, WARM_LED_CONTROL, 0); //打开温水led
		ioctl(gpio_fd, COLD_KEY_CONTROL, 0); //打开冷水阀
		ioctl(gpio_fd, WARM_KEY_CONTROL, 0); //打开温水阀
		close(gpio_fd); //close device
	}
}

void Java_com_ts_host_N_openWarmLed(JNIEnv* env, jobject thiz) {
	int gpio_fd = open(DEVICE_NAME, O_RDWR);
	if (gpio_fd == -1) {//open fail


	}

	else

	{
		ioctl(gpio_fd, WARM_LED_CONTROL, 0); //打开温水led
		close(gpio_fd); //close device
	}
}

void Java_com_ts_host_N_openColdLed(JNIEnv* env, jobject thiz) {
	int gpio_fd = open(DEVICE_NAME, O_RDWR);
	if (gpio_fd == -1) {//open fail


	}

	else

	{
		ioctl(gpio_fd, COLD_LED_CONTROL, 0); //打开冷水led
		close(gpio_fd); //close device
	}
}


void Java_com_ts_host_N_openColdWater(JNIEnv* env, jobject thiz) {
	int gpio_fd = open(DEVICE_NAME, O_RDWR);
	if (gpio_fd == -1) {//open fail


	}

	else

	{
		ioctl(gpio_fd, COLD_KEY_CONTROL, 0); //打开冷水阀
		close(gpio_fd); //close device
	}
}

void Java_com_ts_host_N_openWarmWater(JNIEnv* env, jobject thiz) {
	int gpio_fd = open(DEVICE_NAME, O_RDWR);
	if (gpio_fd == -1) {//open fail


	}

	else

	{
		ioctl(gpio_fd, WARM_KEY_CONTROL, 0); //打开温水阀
		close(gpio_fd); //close device
	}
}
